import Vue from 'vue'
import Vuex from 'vuex'

import  axios from  'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[]
  },
  mutations: {
    mList(state,list){
      state.list=list
    },
    //  添加一条数据到list中
    addVal(state,obj){
      state.list.push(obj)
    },

    //删除数据
    mdel(state,id){
      state.list=state.list.filter(item=>item.id!=id)
    }
  },
  actions: {
    aList({commit}){
      axios.get('/list.json').then(res=>{
        console.log(res,77788);
        commit('mList',res.data)
      })
    }
  },
  getters:{
    num(state){
      return state.list.filter(item=>item.done==false).length
    }
  },
  modules: {
  }
})
